<?php

/* -----------------------------------------------------------------------------------------
   $Id: shop_content.php 2 2011-02-17 13:35:25Z akausch $

   XT-Commerce - community made shopping
   http://www.xt-commerce.com

   Copyright (c) 2003 XT-Commerce
   -----------------------------------------------------------------------------------------
   based on:
   (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
   (c) 2002-2003 osCommerce(conditions.php,v 1.21 2003/02/13); www.oscommerce.com
   (c) 2003	 nextcommerce (shop_content.php,v 1.1 2003/08/19); www.nextcommerce.org

   Released under the GNU General Public License
   ---------------------------------------------------------------------------------------*/

require ('includes/application_top.php');
// create smarty elements
$smarty = new Smarty;
// include boxes
if ($mobile_template == 'False') {
	require (DIR_FS_CATALOG.'templates/'.CURRENT_TEMPLATE.'/source/boxes.php');
} else {
	require (DIR_FS_CATALOG.'templates/'.CURRENT_MOBILE_TEMPLATE.'/source/boxes.php');
}
// include needed functions
require_once (DIR_FS_INC.'xtc_validate_email.inc.php');

if (GROUP_CHECK == 'true') {
	$group_check = "and group_ids LIKE '%c_".$_SESSION['customers_status']['customers_status_id']."_group%'";
}

$shop_content_query = xtDBquery("SELECT
                     content_id,
                     content_title,
                     content_heading,
                     content_text,
                     content_file
                     FROM ".TABLE_CONTENT_MANAGER."
                     WHERE content_group='".(int) $_GET['coID']."' ".$group_check."
                     AND languages_id='".(int) $_SESSION['languages_id']."'");
$shop_content_data = xtc_db_fetch_array($shop_content_query);

$breadcrumb->add($shop_content_data['content_title'], xtc_href_link(FILENAME_CONTENT,'coID='.(int) $_GET['coID']));

if ($_GET['coID'] != 7) {
	require (DIR_WS_INCLUDES.'header.php');
}
if ($_GET['coID'] == 7 && $_GET['action'] == 'success') {
	require (DIR_WS_INCLUDES.'header.php');
}

$smarty->assign('CONTENT_HEADING', $shop_content_data['content_heading']);

if ($_GET['coID'] == 7) {
	include ('display_vvcodes.php');
	$error = false;
	if (isset ($_GET['action']) && ($_GET['action'] == 'send')) {
		if ($_POST['datensg'] == '0') {
			if(xtc_validate_email(trim($_POST['email']))) {
				if (!empty($_POST["stringCaptcha"])) {
					include_once('captcha_math_check.php');
					if($resultCaptcha) {
						$smarty->caching = false;
						require_once (DIR_FS_INC.'cseo_get_mail_body.inc.php');
						$html_mail = nl2br($_POST['message_body']);
						$html_mail .= $smarty->fetch('html:contact');
						$html_mail .= $signatur_html;
						$txt_mail = $_POST['message_body'];
						$txt_mail .= $smarty->fetch('txt:contact');
						$txt_mail .= $signatur_text;
						require_once (DIR_FS_INC.'cseo_get_mail_data.inc.php');
						$mail_data = cseo_get_mail_data('contact');

						// create subject
						$contact_subject = str_replace('{$date}', strftime(DATE_FORMAT_LONG), $mail_data['EMAIL_SUBJECT']);
						$contact_subject = str_replace('{$shop_besitzer}', STORE_OWNER, $contact_subject);
						$contact_subject = str_replace('{$shop_name}', STORE_NAME, $contact_subject);

						// send mail to admin
						xtc_php_mail($_POST['email'], 
										$_POST['name'], 
										$mail_data['EMAIL_ADDRESS'], 
										$mail_data['EMAIL_ADDRESS_NAME'], 
										$mail_data['EMAIL_FORWARD'], 
										$_POST['email'], 
										$_POST['name'], 
										'', 
										'', 
										$contact_subject, 
										$html_mail, 
										$txt_mail);

						if (!isset ($mail_error)) {
							xtc_redirect(xtc_href_link(FILENAME_CONTENT, 'action=success&coID='.(int) $_GET['coID'], 'SSL'));
						} else {
							$smarty->assign('error_message', $mail_error);
						}
					} else {
					$smarty->assign('error_message', TEXT_WRONG_CODE);
					$error = true;
					}
				} else {
					$smarty->assign('error_message', TEXT_WRONG_CODE);
					$error = true;
				}
			} else {
				// error report hier einbauen
				$smarty->assign('error_message', ERROR_MAIL);
				$error = true;
			}
		} else {
			$smarty->assign('error_message', ERROR_CDATENSG);
			$error = true;
		}
	}

	$smarty->assign('CONTACT_HEADING', $shop_content_data['content_title']);
	if (isset ($_GET['action']) && ($_GET['action'] == 'success')) {
		$smarty->assign('success', '1');
		$smarty->assign('BUTTON_CONTINUE', '<a href="'.xtc_href_link(FILENAME_DEFAULT).'">'.xtc_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE).'</a>');

	} else {
		if($shop_content_data['content_file'] != '') {
			ob_start();
			if (strpos($shop_content_data['content_file'], '.txt'))
				echo '<pre>';
			include (DIR_FS_CATALOG.'media/content/'.$shop_content_data['content_file']);
			if (strpos($shop_content_data['content_file'], '.txt'))
				echo '</pre>';
			$contact_content = ob_get_contents();
			ob_end_clean();
		} else {
			$contact_content = $shop_content_data['content_text'];
		}


		require (DIR_WS_INCLUDES.'header.php');
		$smarty->assign('CONTACT_CONTENT', $contact_content);
		$smarty->assign('FORM_ACTION', xtc_draw_form('contact_us', xtc_href_link(FILENAME_CONTENT, 'action=send&coID='.(int) $_GET['coID'], 'SSL')));

	function get_customer_mail($customer_id){
	  $customer_sql = 'select customers_email_address from ' . TABLE_CUSTOMERS . ' where customers_id=' . $customer_id;
	  $customer_array = xtDBquery($customer_sql);
	  $customer_info = xtc_db_fetch_array($customer_array);
	  return $customer_info['customers_email_address'];
	}
    if(isset($_SESSION['customer_id'])) {
		$name = $_SESSION['customer_first_name'] . ' ' . $_SESSION['customer_last_name'];
		$smarty->assign('INPUT_NAME', xtc_draw_input_field('name', $name));
		$smarty->assign('INPUT_EMAIL', xtc_draw_input_field('email', get_customer_mail((int)($_SESSION['customer_id']))));		
		
    } else {
    // Guest
		$name = ($error ? $_POST['name'] : $first_name);
		$smarty->assign('INPUT_NAME', xtc_draw_input_field('name', $name));
		$smarty->assign('INPUT_EMAIL', xtc_draw_input_field('email', ($error ? $_POST['email'] : $email_address)));
    }// else
		$smarty->assign('INPUT_TEXT', xtc_draw_textarea_field('message_body', 'soft', 50, 15, $_POST['message_body']));
		$smarty->assign('VVIMG', '<img src="'.$vvimg.'" alt="Captcha" />'); 
		$smarty->assign('INPUT_CODE', xtc_draw_input_field('stringCaptcha', '', 'size="6" maxlength="6"', 'text', false));
		$smarty->assign('CodeCaptcha', xtc_draw_hidden_field('codeCaptcha', $_SESSION["vvcode"], ''));
		$smarty->assign('BUTTON_SUBMIT', xtc_image_submit('button_continue.gif', IMAGE_BUTTON_SEND));
		$smarty->assign('DATENSG_checkbox',xtc_draw_checkbox_field('datensg', '0'));
		$smarty->assign('FORM_END', '</form>');
	}
		
	$smarty->assign('language', $_SESSION['language']);
	
	$smarty->caching = 0;
	if ($mobile_template == 'False') {
		$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/contact_us.html');
	} else {
		$main_content = $smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/contact_us.html');
	}
	
	

} else {

	if ($shop_content_data['content_file'] != '') {
		ob_start();
		if (strpos($shop_content_data['content_file'], '.txt'))
			echo '<pre>';
		include (DIR_FS_CATALOG.'media/content/'.$shop_content_data['content_file']);
		if (strpos($shop_content_data['content_file'], '.txt'))
			echo '</pre>';
		$smarty->assign('file', ob_get_contents());
		ob_end_clean();

	} else {
		$content_body = $shop_content_data['content_text'];
	}
	$smarty->assign('CONTENT_BODY', $content_body);
	$smarty->assign('PDF_LINK','<a href="'.xtc_href_link(FILENAME_PRINT_PDF,'content='.$_GET['coID']).'">'.xtc_image('images/button_pdf.gif',IMAGE_BUTTON_PRINT_PDF).'</a>');
	$smarty->assign('PRINT_LINK','<a href="javascript:popupWindowShipping(\''.xtc_href_link(FILENAME_POPUP_CONTENT,'coID='.$_GET['coID']).'\')">'.xtc_image('images/button_print.gif',IMAGE_BUTTON_PRINT_CONTENT).'</a>');
	$smarty->assign('BUTTON_CONTINUE', '<a href="javascript:history.back(1)">'.xtc_image_button('button_back.gif', IMAGE_BUTTON_BACK).'</a>');
	$smarty->assign('language', $_SESSION['language']);

	// set cache ID
	 if (!CacheCheck()) {
		$smarty->caching = 0;
		if ($mobile_template == 'False') {
			$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/content.html');
		} else {
			$main_content = $smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/content.html');
		}		
	} else {
		$smarty->caching = 1;
		$smarty->cache_lifetime = CACHE_LIFETIME;
		$smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $_SESSION['language'].$shop_content_data['content_id'];
		if ($mobile_template == 'False') {
			$main_content = $smarty->fetch(CURRENT_TEMPLATE.'/module/content.html', $cache_id);
		} else {
			$main_content = $smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/content.html', $cache_id);
		}
	}

}

$smarty->assign('language', $_SESSION['language']);
$smarty->assign('main_content', $main_content);
$smarty->caching = 0;
if (!defined(RM))
	$smarty->load_filter('output', 'note');
	
if ($mobile_template == 'False') {
	$smarty->display(CURRENT_TEMPLATE.'/index.html');
} else {
	$smarty->display(CURRENT_MOBILE_TEMPLATE.'/index.html');
}	
include ('includes/application_bottom.php');
?>